#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>

int main(int argc, char ** argv) {
    if(argc != 2) {
        perror("参数个数错误!");
        exit(-1);
    }

    const char * web = argv[1];
    struct hostent * phost = gethostbyname(web);
    
    printf("Official name of host: %s\n", phost->h_name);

    printf("------------------------------------------\n");
    printf("Alias list:\n");
    char ** alias = phost->h_aliases;
    int i = 0;
    while(*alias) {
        printf("%d: %s\n", i++, *alias++);
    }

    printf("------------------------------------------\n");
    printf("Addresses:\n");
    char ** addr = phost->h_addr_list;
    i = 0;
    while(*addr) {
        printf("%d: %s\n", i++, *addr++);
    }
    
    return 0;
}


